import 'package:flutter/material.dart';
import 'paypal_payment_page.dart';

class PayplyPage extends StatelessWidget {
  final String tokenizationKey =
      "Ad3Rhi-2-PDng-m4RJ5HllObSpftKcZ22Solr6wvEG-k3_EZsddES02nPynfvDYbYf_HfeJwLXIPWqZF";

  const PayplyPage({super.key}); // 替换为您的 Tokenization Key

  Future<void> navigateToPaymentPage(BuildContext context) async {
    final result = await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => PayPalPaymentPage(
          tokenizationKey: tokenizationKey,
          initialAmount: "10.00",
        ),
      ),
    );

    if (result != null) {
      // ignore: use_build_context_synchronously
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text("Payment Result: $result")),
      );
    } else {
      // ignore: use_build_context_synchronously
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text("Payment Cancelled")),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("PayPal Payment Demo")),
      body: Center(
        child: ElevatedButton(
          onPressed: () => navigateToPaymentPage(context),
          child: const Text("Go to PayPal Payment Page"),
        ),
      ),
    );
  }
}
